#pragma warning (disable : 4005 )

#include "DXUT.h"
#include "DXUTgui.h"
#include "DXUTmisc.h"
#include "DXUTCamera.h"
#include "DXUTSettingsDlg.h"
#include "SDKmisc.h"
#include "SDKmesh.h"
#include "resource.h"

#include <io.h> 
#include <fcntl.h> 

#include "MainHeader.h"

#ifdef RENDER
#include "HUD.h"

//--------------------------------------------------------------------------------------
// Global variables
//--------------------------------------------------------------------------------------
CFirstPersonCamera          g_Camera;               // A model viewing camera
HUDDialogResourceManager	g_DialogResourceManager; // manager for shared resources of dialogs
CD3DSettingsDlg             g_SettingsDlg;          // Device settings dialog
CDXUTTextHelper*            g_pTxtHelper = NULL;
CDXUTDialog                 g_HUD;                  // dialog for standard controls
CDXUTDialog                 g_SampleUI;             // dialog for sample specific controls

HUDDialog					g_LifeHUD;

// Direct3D 9 resources
extern ID3DXFont*           g_pFont9;
extern ID3DXSprite*         g_pSprite9;

bool    g_bLeftButtonDown = false;
bool    g_bRightButtonDown = false;
bool    g_bMiddleButtonDown = false;

HWND hWindow = NULL;
bool cursorlock = false;

#endif

#ifdef SERVER
ServerWorld*					g_sWorld;
#endif

#ifdef CLIENT
#ifdef MULTIPLAYER
ClientWorld*					g_World;
#else
RenderableWorld*				g_World;
#endif
#endif

#ifdef RENDER
//--------------------------------------------------------------------------------------
// UI control IDs
//--------------------------------------------------------------------------------------
#define IDC_TOGGLEFULLSCREEN    1
#define IDC_TOGGLEREF           2
#define IDC_CHANGEDEVICE        3

//--------------------------------------------------------------------------------------
// Forward declarations 
//--------------------------------------------------------------------------------------
LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing,
	void* pUserContext );
void CALLBACK OnKeyboard( UINT nChar, bool bKeyDown, bool bAltDown, void* pUserContext );
void CALLBACK MouseProc( bool bLeftButtonDown, bool bRightButtonDown, bool bMiddleButtonDown, bool bSideButton1Down,
	bool bSideButton2Down, int nMouseWheelDelta, int xPos, int yPos, void* pUserContext );
void CALLBACK OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext );
void CALLBACK OnFrameMove( double fTime, float fElapsedTime, void* pUserContext );
bool CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, void* pUserContext );

extern bool CALLBACK IsD3D9DeviceAcceptable( D3DCAPS9* pCaps, D3DFORMAT AdapterFormat, D3DFORMAT BackBufferFormat,
	bool bWindowed, void* pUserContext );
extern HRESULT CALLBACK OnD3D9CreateDevice( IDirect3DDevice9* pd3dDevice,
	const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext );
extern HRESULT CALLBACK OnD3D9ResetDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc,
	void* pUserContext );
extern void CALLBACK OnD3D9FrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime,
	void* pUserContext );
extern void CALLBACK OnD3D9LostDevice( void* pUserContext );
extern void CALLBACK OnD3D9DestroyDevice( void* pUserContext );

bool CALLBACK IsD3D11DeviceAcceptable( const CD3D11EnumAdapterInfo *AdapterInfo, UINT Output, const CD3D11EnumDeviceInfo *DeviceInfo,
	DXGI_FORMAT BackBufferFormat, bool bWindowed, void* pUserContext );
HRESULT CALLBACK OnD3D11CreateDevice( ID3D11Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc,
	void* pUserContext );
HRESULT CALLBACK OnD3D11ResizedSwapChain( ID3D11Device* pd3dDevice, IDXGISwapChain* pSwapChain,
	const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext );
void CALLBACK OnD3D11ReleasingSwapChain( void* pUserContext );
void CALLBACK OnD3D11DestroyDevice( void* pUserContext );
void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, double fTime,
	float fElapsedTime, void* pUserContext );

void InitApp();
void RenderText();

#endif

//--------------------------------------------------------------------------------------
// Entry point to the program. Initializes everything and goes into a message processing 
// loop. Idle time is used to render the scene.
//--------------------------------------------------------------------------------------
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow )
{
	if (AllocConsole()) {
		FILE *stream;
		freopen_s( &stream, "CONIN$",  "r", stdin);
		freopen_s( &stream, "CONOUT$", "w", stdout);
		freopen_s( &stream, "CONOUT$", "w", stderr);
	}
#ifdef SERVER
	/* init */
	g_sWorld = new ServerWorld();

	/* loop */
	string input = "";
	cout << "Server sarted...\n";
	while (true) {
		getline(cin, input);
		if (input.compare("/close") == 0)
			break;
	};

	/* finally */
	SAFE_DELETE( g_sWorld );

	return 0;
#endif

#ifdef CLIENT
	// Enable run-time memory check for debug builds.
#if defined(DEBUG) | defined(_DEBUG)
	_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif

	// DXUT will create and use the best device (either D3D9 or D3D11) 
	// that is available on the system depending on which D3D callbacks are set below

	// Set DXUT callbacks
	DXUTSetCallbackMsgProc( MsgProc );
	DXUTSetCallbackKeyboard( OnKeyboard );
	DXUTSetCallbackMouse( MouseProc );
	DXUTSetCallbackFrameMove( OnFrameMove );
	DXUTSetCallbackDeviceChanging( ModifyDeviceSettings );

	DXUTSetCallbackD3D9DeviceAcceptable( IsD3D9DeviceAcceptable );
	DXUTSetCallbackD3D9DeviceCreated( OnD3D9CreateDevice );
	DXUTSetCallbackD3D9DeviceReset( OnD3D9ResetDevice );
	DXUTSetCallbackD3D9DeviceLost( OnD3D9LostDevice );
	DXUTSetCallbackD3D9DeviceDestroyed( OnD3D9DestroyDevice );
	DXUTSetCallbackD3D9FrameRender( OnD3D9FrameRender );

	DXUTSetCallbackD3D11DeviceAcceptable( IsD3D11DeviceAcceptable );
	DXUTSetCallbackD3D11DeviceCreated( OnD3D11CreateDevice );
	DXUTSetCallbackD3D11SwapChainResized( OnD3D11ResizedSwapChain );
	DXUTSetCallbackD3D11SwapChainReleasing( OnD3D11ReleasingSwapChain );
	DXUTSetCallbackD3D11DeviceDestroyed( OnD3D11DestroyDevice );
	DXUTSetCallbackD3D11FrameRender( OnD3D11FrameRender );

	InitApp();

	//g_HUD.SetTexture(0, L"terrain.png");
	DXUTCreateWindow( L"B++" );

//	hWindow = DXUTGetHWNDDeviceWindowed();

#ifdef MULTIPLAYER
	g_World = new ClientWorld( &g_Camera, &g_DialogResourceManager );
#else
	g_World = new RenderableWorld( &g_Camera, &g_DialogResourceManager );
#endif

	DXUTInit( true, true, NULL, true ); // Parse the command line, show msgboxes on error, no extra command line params

	//Curser settings
	DXUTSetCursorSettings( true, false );


	// Only require 10-level hardware, change to D3D_FEATURE_LEVEL_11_0 to require 11-class hardware
	// Switch to D3D_FEATURE_LEVEL_9_x for 10level9 hardware
	//g_World = new World( NULL );

	DXUTCreateDevice( D3D_FEATURE_LEVEL_10_0, true, 1024, 768 );
	//DXUTCreateDevice( D3D_FEATURE_LEVEL_10_0, false, 1920, 1080 );

	DXUTMainLoop(); // Enter into the DXUT render loop

	//SAFE_DELETE( g_Region );
	SAFE_DELETE( g_World );

	return DXUTGetExitCode();
#endif
}

#ifdef RENDER
//--------------------------------------------------------------------------------------
// Initialize the app 
//--------------------------------------------------------------------------------------
void InitApp()
{
	g_SettingsDlg.Init( &g_DialogResourceManager );
	g_HUD.Init( &g_DialogResourceManager );
	g_SampleUI.Init( &g_DialogResourceManager );

	g_LifeHUD.Init( &g_DialogResourceManager );

//	CDXUTElement
	g_HUD.SetCallback( OnGUIEvent );
	int iY = 30;
	int iYo = 26;
	g_HUD.AddButton( IDC_TOGGLEFULLSCREEN, L"Toggle full screen", 0, iY, 170, 22 );
	g_HUD.AddButton( IDC_TOGGLEREF, L"Toggle REF (F3)", 0, iY += iYo, 170, 22, VK_F3 );
	g_HUD.AddButton( IDC_CHANGEDEVICE, L"Change device (F2)", 0, iY += iYo, 170, 22, VK_F2 );

	//g_LifeHUD.AddLifebar( 4, 0, 40, 500, 20);
	g_LifeHUD.AddCursor( 5 );
	/*
	HUDBlock * block = NULL;
	g_LifeHUD.AddBlock( 5, &block);

	block->addBlock(300, 720, 1);
	block->addBlock(350, 720, 2);
	block->addBlock(400, 720, 3);
	block->addBlock(450, 720, 4);
	block->addBlock(500, 720, 20);
	block->addBlock(550, 720, 10);
	block->addBlock(600, 720, 14);
	block->addBlock(650, 720, 16);
	block->addBlock(700, 720, 100);
	block->addBlock(750, 720, 102);

	g_LifeHUD.AddSelected( 6, 275, 695, 50, 50);
	*/
	g_SampleUI.SetCallback( OnGUIEvent ); iY = 10;

	// Setup the camera's view parameters
	D3DXVECTOR3 vecEye( 0.0f, 124.0f, 5.0f );
	D3DXVECTOR3 vecAt ( 0.0f, 110.0f, 10.0f );

	g_Camera.SetViewParams( &vecEye, &vecAt );
	g_Camera.SetRotateButtons( true, true, true, true );
	//g_Camera.SetEnablePositionMovement( true );
	g_Camera.SetScalers(0.01f, 20.0f);

}


//--------------------------------------------------------------------------------------
// Render the help and statistics text. This function uses the ID3DXFont interface for 
// efficient text rendering.
//--------------------------------------------------------------------------------------
void RenderText()
{
	g_pTxtHelper->Begin();
	g_pTxtHelper->SetInsertionPos( 5, 5 );
	g_pTxtHelper->SetForegroundColor( D3DXCOLOR( 1.0f, 1.0f, 0.0f, 1.0f ) );
	g_pTxtHelper->DrawTextLine( DXUTGetFrameStats( DXUTIsVsyncEnabled() ) );
	g_pTxtHelper->DrawTextLine( DXUTGetDeviceStats() );
	g_pTxtHelper->End();
}


//--------------------------------------------------------------------------------------
// Reject any D3D11 devices that aren't acceptable by returning false
//--------------------------------------------------------------------------------------
bool CALLBACK IsD3D11DeviceAcceptable( const CD3D11EnumAdapterInfo *AdapterInfo, UINT Output, const CD3D11EnumDeviceInfo *DeviceInfo,
	DXGI_FORMAT BackBufferFormat, bool bWindowed, void* pUserContext )
{
	return true;
}


//--------------------------------------------------------------------------------------
// Create any D3D11 resources that aren't dependant on the back buffer
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D11CreateDevice( ID3D11Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc,
	void* pUserContext )
{
	HRESULT hr;

	ID3D11DeviceContext* pd3dImmediateContext = DXUTGetD3D11DeviceContext();
	V_RETURN( g_DialogResourceManager.OnD3D11CreateDevice( pd3dDevice, pd3dImmediateContext ) );
	V_RETURN( g_SettingsDlg.OnD3D11CreateDevice( pd3dDevice ) );

	g_pTxtHelper = new CDXUTTextHelper( pd3dDevice, pd3dImmediateContext, &g_DialogResourceManager, 15 );

	if (g_World )
		g_World->OnD3D11CreateDevice( pd3dDevice, pd3dImmediateContext, pBackBufferSurfaceDesc, pUserContext );

	return S_OK;
}

//--------------------------------------------------------------------------------------
// Create any D3D11 resources that depend on the back buffer
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D11ResizedSwapChain( ID3D11Device* pd3dDevice, IDXGISwapChain* pSwapChain,
	const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
{
	HRESULT hr;

	V_RETURN( g_DialogResourceManager.OnD3D11ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ) );
	V_RETURN( g_SettingsDlg.OnD3D11ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ) );

	float fAspectRatio = pBackBufferSurfaceDesc->Width / ( FLOAT )pBackBufferSurfaceDesc->Height;
	g_Camera.SetProjParams( D3DX_PI / 4, fAspectRatio, 0.1f, 300.0f );

	g_HUD.SetLocation( pBackBufferSurfaceDesc->Width - 170, 0 );
	g_HUD.SetSize( 170, 170 );

	g_LifeHUD.SetLocation( 0, 0 );
	g_LifeHUD.SetSize( 0, 0 );

	g_SampleUI.SetLocation( pBackBufferSurfaceDesc->Width - 170, pBackBufferSurfaceDesc->Height - 300 );
	g_SampleUI.SetSize( 170, 300 );

	if (g_World )
		g_World->OnD3D11ResizedSwapChain( pd3dDevice, pSwapChain, pBackBufferSurfaceDesc, pUserContext );


	//g_HUD.SetTexture(0, L"UI/dxutcontrols.dds");

	return S_OK;
}


//--------------------------------------------------------------------------------------
// Render the scene using the D3D11 device
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, double fTime,
	float fElapsedTime, void* pUserContext )
{



	// If the settings dialog is being shown, then render it instead of rendering the app's scene
	if( g_SettingsDlg.IsActive() )
	{
		g_SettingsDlg.OnRender( fElapsedTime );
		return;
	}       
/*
	float ClearColor[4] = { 0.176f, 0.196f, 0.667f, 0.0f };
	ID3D11RenderTargetView* pRTV = DXUTGetD3D11RenderTargetView();
	pd3dImmediateContext->ClearRenderTargetView( pRTV, ClearColor );

	// Clear the depth stencil
	ID3D11DepthStencilView* pDSV = DXUTGetD3D11DepthStencilView();
	pd3dImmediateContext->ClearDepthStencilView( pDSV, D3D11_CLEAR_DEPTH, 1.0, 0 );
*/

	g_World->OnD3D11FrameRender( pd3dDevice, pd3dImmediateContext, fTime, fElapsedTime, pUserContext );

	DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" );
	g_HUD.OnRender( fElapsedTime );
	g_LifeHUD.OnRender( fElapsedTime );
	g_SampleUI.OnRender( fElapsedTime );
	//RenderText();
	DXUT_EndPerfEvent();

	static DWORD dwTimefirst = GetTickCount();
	if ( GetTickCount() - dwTimefirst > 5000 )
	{    
		OutputDebugString( DXUTGetFrameStats( DXUTIsVsyncEnabled() ) );
		OutputDebugString( L"\n" );
		dwTimefirst = GetTickCount();
	}
}


//--------------------------------------------------------------------------------------
// Release D3D11 resources created in OnD3D11ResizedSwapChain 
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D11ReleasingSwapChain( void* pUserContext )
{
	g_DialogResourceManager.OnD3D11ReleasingSwapChain();
	if (g_World )
		g_World->OnD3D11ReleasingSwapChain( pUserContext );
}


//--------------------------------------------------------------------------------------
// Release D3D11 resources created in OnD3D11CreateDevice 
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D11DestroyDevice( void* pUserContext )
{
	if (g_World )
		g_World->OnD3D11DestroyDevice( pUserContext );

	g_DialogResourceManager.OnD3D11DestroyDevice();
	g_SettingsDlg.OnD3D11DestroyDevice();
	DXUTGetGlobalResourceCache().OnDestroyDevice();
	SAFE_DELETE( g_pTxtHelper );
}


//--------------------------------------------------------------------------------------
// Called right before creating a D3D9 or D3D11 device, allowing the app to modify the device settings as needed
//--------------------------------------------------------------------------------------
bool CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, void* pUserContext )
{
	if( pDeviceSettings->ver == DXUT_D3D9_DEVICE )
	{
		IDirect3D9* pD3D = DXUTGetD3D9Object();
		D3DCAPS9 Caps;
		pD3D->GetDeviceCaps( pDeviceSettings->d3d9.AdapterOrdinal, pDeviceSettings->d3d9.DeviceType, &Caps );

		// If device doesn't support HW T&L or doesn't support 1.1 vertex shaders in HW 
		// then switch to SWVP.
		if( ( Caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT ) == 0 ||
			Caps.VertexShaderVersion < D3DVS_VERSION( 1, 1 ) )
		{
			pDeviceSettings->d3d9.BehaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
		}

		// Debugging vertex shaders requires either REF or software vertex processing 
		// and debugging pixel shaders requires REF.  
#ifdef DEBUG_VS
		if( pDeviceSettings->d3d9.DeviceType != D3DDEVTYPE_REF )
		{
			pDeviceSettings->d3d9.BehaviorFlags &= ~D3DCREATE_HARDWARE_VERTEXPROCESSING;
			pDeviceSettings->d3d9.BehaviorFlags &= ~D3DCREATE_PUREDEVICE;
			pDeviceSettings->d3d9.BehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
		}
#endif
#ifdef DEBUG_PS
		pDeviceSettings->d3d9.DeviceType = D3DDEVTYPE_REF;
#endif
	}

	// For the first device created if its a REF device, optionally display a warning dialog box
	static bool s_bFirstTime = true;
	if( s_bFirstTime )
	{
		s_bFirstTime = false;
		if( ( DXUT_D3D9_DEVICE == pDeviceSettings->ver && pDeviceSettings->d3d9.DeviceType == D3DDEVTYPE_REF ) ||
			( DXUT_D3D11_DEVICE == pDeviceSettings->ver &&
			pDeviceSettings->d3d11.DriverType == D3D_DRIVER_TYPE_REFERENCE ) )
		{
			DXUTDisplaySwitchingToREFWarning( pDeviceSettings->ver );
		}

	}

	return true;
}


//--------------------------------------------------------------------------------------
// Handle updates to the scene.  This is called regardless of which D3D API is used
//--------------------------------------------------------------------------------------
void CALLBACK OnFrameMove( double fTime, float fElapsedTime, void* pUserContext )
{
	// Update the camera's position based on user input 
	g_World->FrameMove( fTime, fElapsedTime );
	g_Camera.FrameMove( fElapsedTime );
}


//--------------------------------------------------------------------------------------
// Handle mouse buttons
//--------------------------------------------------------------------------------------
void CALLBACK MouseProc( bool bLeftButtonDown, bool bRightButtonDown, bool bMiddleButtonDown, bool bSideButton1Down,
	bool bSideButton2Down, int nMouseWheelDelta, int xPos, int yPos, void* pUserContext )
{/*
	bool bOldLeftButtonDown = g_bLeftButtonDown;
	bool bOldRightButtonDown = g_bRightButtonDown;
	bool bOldMiddleButtonDown = g_bMiddleButtonDown;*/
	g_bLeftButtonDown = bLeftButtonDown;
	g_bMiddleButtonDown = bMiddleButtonDown;
	g_bRightButtonDown = bRightButtonDown;
	/*
	if( bOldLeftButtonDown && !g_bLeftButtonDown )
		g_Camera.SetEnablePositionMovement( false );
	else if( !bOldLeftButtonDown && g_bLeftButtonDown )
		g_Camera.SetEnablePositionMovement( true );

	else if( !bOldRightButtonDown && g_bRightButtonDown )
	{
		g_Camera.SetEnablePositionMovement( false );
	}

	else if( !bOldMiddleButtonDown && g_bMiddleButtonDown )
	{
		g_Camera.SetEnablePositionMovement( false );
	}

	// If no mouse button is down at all, enable camera movement.
	if( !g_bLeftButtonDown && !g_bRightButtonDown && !g_bMiddleButtonDown )
		g_Camera.SetEnablePositionMovement( true );*/
	g_World->handleMouse( bLeftButtonDown, bRightButtonDown, bMiddleButtonDown, bSideButton1Down, bSideButton2Down, nMouseWheelDelta, xPos, yPos, pUserContext );
}

//--------------------------------------------------------------------------------------
// Handle messages to the application
//--------------------------------------------------------------------------------------
LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing,
	void* pUserContext )
{

#ifdef CLIENT
	g_World->MsgProc( hWnd, uMsg, wParam, lParam );
#endif

	// Pass messages to dialog resource manager calls so GUI state is updated correctly
	*pbNoFurtherProcessing = g_DialogResourceManager.MsgProc( hWnd, uMsg, wParam, lParam );
	if( *pbNoFurtherProcessing )
		return 0;

	// Pass messages to settings dialog if its active
	if( g_SettingsDlg.IsActive() )
	{
		g_SettingsDlg.MsgProc( hWnd, uMsg, wParam, lParam );
		return 0;
	}

	// Give the dialogs a chance to handle the message first
	*pbNoFurtherProcessing = g_HUD.MsgProc( hWnd, uMsg, wParam, lParam );
	if( *pbNoFurtherProcessing )
		return 0;
	*pbNoFurtherProcessing = g_LifeHUD.MsgProc( hWnd, uMsg, wParam, lParam );
	if( *pbNoFurtherProcessing )
		return 0;
	*pbNoFurtherProcessing = g_SampleUI.MsgProc( hWnd, uMsg, wParam, lParam );
	if( *pbNoFurtherProcessing )
		return 0;

	// Pass all remaining windows messages to camera so it can respond to user input
	//g_Camera.HandleMessages( hWnd, uMsg, wParam, lParam );
	/*
	if (uMsg == WM_MOUSEMOVE) {

		currMousePos.x = ( short )LOWORD( lParam );
		currMousePos.y = ( short )HIWORD( lParam );

		POINT difference;
		difference.x = currMousePos.x - lastMousePos.x;
		difference.y = currMousePos.y - lastMousePos.y;

		lastMousePos = currMousePos;

		// INFO: the special case
		if(!PtInRect(&safeArea, currMousePos))
		{
			POINT temp = resetMousePos;
			ClientToScreen(hWnd, &temp);

			// the new difference should be 0
			currMousePos.x = resetMousePos.x;
			currMousePos.y = resetMousePos.y;
			lastMousePos = currMousePos;

			SetCursorPos(temp.x, temp.y);
		}

		//g_Camera.HandleMessages( hWnd, uMsg, wParam, lParam );
	} else if ((uMsg == WM_KEYDOWN) || (uMsg == WM_KEYUP)) {
		//g_Camera.HandleMessages( hWnd, uMsg, wParam, lParam );
	}*/
	g_Camera.HandleMessages( hWnd, uMsg, wParam, lParam );
	return 0;
}


//--------------------------------------------------------------------------------------
// Handle key presses
//--------------------------------------------------------------------------------------
void CALLBACK OnKeyboard( UINT nChar, bool bKeyDown, bool bAltDown, void* pUserContext )
{
	g_World->handleKeyboard(nChar, bKeyDown, bAltDown, pUserContext );
    if( bKeyDown )
    {
        switch( nChar )
        {
            case 0x49:
                g_Camera.SetResetCursorAfterMove( !cursorlock );
				ShowCursor( cursorlock );
				cursorlock  = !cursorlock;
				break;
        }
    }
}


//--------------------------------------------------------------------------------------
// Handles the GUI events
//--------------------------------------------------------------------------------------
void CALLBACK OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext )
{
	switch( nControlID )
	{
	case IDC_TOGGLEFULLSCREEN:
		//DXUTToggleFullScreen();
		break;
	case IDC_TOGGLEREF:
		//DXUTToggleREF();
		break;
	case IDC_CHANGEDEVICE:
		g_SettingsDlg.SetActive( !g_SettingsDlg.IsActive() );
		break;
	}
}

#endif /* CLIENT */

#ifdef SERVER


#endif /* SERVER */